<?php
class Z1chithikhsController extends AppController {

	var $name = 'Z1chithikhs';
	var $helpers = array('Html', 'Form');
    var $uses=array('Z1chithikh','Donvi');
    var $paginate=array('order'=>array('ngaybd'=>'DESC'),'limit' => 100);

	function index($donvi) {
		$nam = $this->Z1chithikh->find('list',array(
	    										'conditions'=>array('donvi_id'=>$donvi),
	    										'fields'=>array('ngaybd'),
	    										'order'=>array('ngaybd DESC')));
    		foreach ($nam as $key => $value) 
    		{
    			$nams[date('Y',strtotime($value))]=date('Y',strtotime($value)); 
    		}
    	$namht = date('Y');	   
		$this->Z1chithikh->recursive = -1;
		$this->set('z1chithikhthangs', $this->paginate(array(array('donvi_id'=>$donvi,'DATEDIFF(Z1chithikh.ngaykt,Z1chithikh.ngaybd) >='=>7,'YEAR(Z1chithikh.ngaybd)'=>$namht))));
		$this->set('z1chithikhtuans', $this->paginate(array(array('donvi_id'=>$donvi,'DATEDIFF(Z1chithikh.ngaykt,Z1chithikh.ngaybd) <'=>7,'YEAR(Z1chithikh.ngaybd)'=>$namht))));
        $this->Donvi->recursive = -1;
        $dv=$this->Donvi->find('first',array(
                    'conditions'=>array('id'=>$donvi),
                    'fields'=>array('tendv')));
        $this->set(compact('dv','donvi','nams'));
	}
    
	function indexnv($donvi) {
		$nam = $this->Z1chithikh->find('list',array(
	    										'conditions'=>array('donvi_id'=>$donvi),
	    										'fields'=>array('ngaybd'),
	    										'order'=>array('ngaybd DESC')));
    		foreach ($nam as $key => $value) 
    		{
    			$nams[date('Y',strtotime($value))]=date('Y',strtotime($value)); 
    		}
    		
    	$namht = date('Y');	   
		$this->Z1chithikh->recursive = -1;
		
		$this->set('z1chithikhthangs', $this->paginate(array(array('donvi_id'=>$donvi,'DATEDIFF(Z1chithikh.ngaykt,Z1chithikh.ngaybd) >='=>7,'YEAR(Z1chithikh.ngaybd)'=>$namht))));
		$this->set('z1chithikhtuans', $this->paginate(array(array('donvi_id'=>$donvi,'DATEDIFF(Z1chithikh.ngaykt,Z1chithikh.ngaybd) <'=>7,'YEAR(Z1chithikh.ngaybd)'=>$namht))));
        $this->Donvi->recursive = -1;
        $dv=$this->Donvi->find('first',array(
                    'conditions'=>array('id'=>$donvi),
                    'fields'=>array('tendv')));
        $this->set(compact('dv','donvi','nams'));
	}
	
	function ajaxindex($donvi)
	{
		$this->layout='ajax';
    	$namht =$this->data['Z1chithikhs']['nam'];	   
		$this->Z1chithikh->recursive = -1;
		$this->Z1chithikh->recursive = -1;
		$this->set('z1chithikhthangs', $this->paginate(array(array('donvi_id'=>$donvi,'DATEDIFF(Z1chithikh.ngaykt,Z1chithikh.ngaybd) >='=>7,'YEAR(Z1chithikh.ngaybd)'=>$namht))));
		$this->set('z1chithikhtuans', $this->paginate(array(array('donvi_id'=>$donvi,'DATEDIFF(Z1chithikh.ngaykt,Z1chithikh.ngaybd) <'=>7,'YEAR(Z1chithikh.ngaybd)'=>$namht))));
		$this->Donvi->recursive = -1;
        $dv=$this->Donvi->find('first',array(
                    'conditions'=>array('id'=>$donvi),
                    'fields'=>array('tendv')));
        $this->set(compact('dv','donvi'));		
	}
	
	function ajaxindexnv($donvi)
	{
		$this->layout='ajax';
    	$namht =$this->data['Z1chithikhs']['nam'];
    		 
		$this->Z1chithikh->recursive = -1;
		$this->set('z1chithikhthangs', $this->paginate(array(array('donvi_id'=>$donvi,'DATEDIFF(Z1chithikh.ngaykt,Z1chithikh.ngaybd) >='=>7,'YEAR(Z1chithikh.ngaybd)'=>$namht))));
		$this->set('z1chithikhtuans', $this->paginate(array(array('donvi_id'=>$donvi,'DATEDIFF(Z1chithikh.ngaykt,Z1chithikh.ngaybd) <'=>7,'YEAR(Z1chithikh.ngaybd)'=>$namht))));
        $this->Donvi->recursive = -1;
        $dv=$this->Donvi->find('first',array(
                    'conditions'=>array('id'=>$donvi),
                    'fields'=>array('tendv')));
        $this->set(compact('dv','donvi','nams'));
	}
}
?>